
    <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    <script id="varTemplate" type="text/html">
        <select name="selFlowVar" class="selFlowVar" lay-verify="required" lay-filter="selFlowVar">
            <option value="">请选择</option>
            {{#  layui.each(d, function(index, item){ }}
            <option value='{{ item.varKey }}'>{{ item.varName }}</option>
            {{#  }); }}
        </select>
    </script>
    <form class="otherParam layui-form" lay-filter="otherParam">
        <div class="layui-input-block" style="margin-left: 10px">
            <a class="layui-btn save">保存</a>
        </div>
        <table class="table-detail ">
            <tr>
                <th style="width: 15%">流程标题规则定义:</th>
                <td>
                    <div class="layui-form-item" style="margin: 10px 0 0 0">
                        <label class="layui-form-label">表单变量：</label>
                        <div class="layui-input-block" id="view">
                        </div>
                        <textarea id="taskNameRule" class="layui-textarea" style="margin-right: 10px;"></textarea>
                    </div>

            </td>
        </tr>
        <tr>
            <th>跳过第一个任务:</th>
            <td >
                <input id="toFirstNode" lay-skin="primary" type="checkbox"  name="toFirstNode" lay-skin="primary" value="0"/>&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="nextTask" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>

            </td>
        </tr>
<!--        <tr>
            <th>直接启动流程:</th>
            <td>
                <input id="directstart" type="checkbox" lay-skin="primary" name="directstart" value="0"/>&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="startHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>-->
        <tr>
            <th>流程启动选择执行人:</th>
            <td>
                <input id="showFirstAssignee" type="checkbox" lay-skin="primary" lay-skin="primary" lay-skin="primary" name="showFirstAssignee" value="0" />&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="choiceHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>
<!--        <tr>
            <th>提交是否需要确认:</th>
            <td>
                <input id="submitConfirm" type="checkbox" lay-skin="primary" name="submitConfirm" value="0" />&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="submitHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>-->
        <tr>
            <th>是否允许转办:</th>
            <td>
                <input id="allowDivert" type="checkbox" lay-skin="primary" name="allowDivert" value="0" />&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="changeHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>
        <tr>
            <th>是否允许我的办结转发:</th>
            <td>
                <input id="allowFinishedDivert" type="checkbox" lay-skin="primary" name="allowFinishedDivert" value="0" />&nbsp;
                <div class="text-adjust">
                    <a href="javascript:;"  id="endHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>
        <tr>
            <th>归档时发送消息给发起人:</th>
            <td>
                <div class="layui-input-inline" id="informStartDiv">
                    <#list handlersMap?keys as key>
                    <input type="checkbox" lay-skin="primary" name="informStart" value="${key}" ><div class='text-adjust'>${handlersMap[key].title}</div>
                </#list>
                </div>
            </td>
        </tr>
        <tr>
            <th>是否允许办结抄送:</th>
            <td >
                <div >
                    <input id="allowFinishedCc" type="checkbox" lay-skin="primary" name="allowFinishedCc" value="0"  />
                    <!-- 抄送消息提醒方式 -->
                    <input class="send_type" name="ccMessageType" type="hidden" />
                    <div class="text-adjust copyingPeople" style="cursor: pointer;">抄送人员设置</div>
                    <div class="text-adjust">
                        <a href="javascript:;"  id="copyHint" ><i class="iconfont iconicon_yiwenkongxin"></i></a>
                    </div>
                </div>
            </td>
        </tr>
        <!--<tr>
            <th>流程实例归档后是否允许打印表单:</th>
            <td >
                <div class="text-adjust">
                    <input id="isPrintForm" type="checkbox" lay-skin="primary" name="isPrintForm" value="0" />&nbsp;
                    <a href="javascript:;"  id="printHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
                </div>
            </td>
        </tr>-->
        <tr>
            <th>流程帮助:</th>
            <td>
                <input id="attachment" type="hidden" name="attachment"/>
                <span id="attachmentSpan" hidden>
                    <a  id="selectedFileUrl"><label id="selectedFileName"></label></a>
                    <a  id="delAttachment" style='color:#FF5722'><i class="layui-icon layui-icon-delete"></i>删除</a>
                </span>
                <a id="selectedFile" name="selectedFile" class="layui-btn layui-btn-sm selectedFile" lay-data="{url: '/b/', accept: 'file'}">添加附件</a>&nbsp;
                <a href="javascript:;"  id="helpHint" ><i class="iconfont iconicon_yiwenkongxin" style="font-size: 20px"></i></a>
            </td>
        </tr>
        <tr>
            <th>流程参考:</th>
            <td>
                <div style="float: left">
                    <input id="allowRefer" type="checkbox" lay-filter="allowReferChange" lay-skin="primary" name="allowRefer" value="0" /><div class="text-adjust">允许参考</div>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>

                <span id="spanInstanceAmount" style="display: none">
                    <label class="text-adjust">参考条数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="instanceAmount" name="instanceAmount" class="layui-input" style="width: 50px;">
                    </div>
                </span>
            </td>
        </tr>
        <tr>
            <th>状态:</th>
            <td>
                <div class="layui-form-item" style="margin: 0px; float: left;height: 33px;">
                    <select id="status" name="status" lay-filter="statusChange" style="margin-top: 5px" lay-verify="required">
                        <option value="1">启用</option>
                        <option value="2">禁用</option>
                        <option value="3">禁用(实例)</option>
                        <option value="4">测试</option>
                    </select>
                    &nbsp;&nbsp;
                </div>
                <div class="layui-inline" id="spanMessage" style="float: left;margin-right: 8px">
                    <div class="layui-input-inline" id="informTypeDiv">
                        <#list handlersMap?keys as key>
                        <input type="checkbox" lay-skin="primary" name="informType" value="${key}" ><div class='text-adjust'>${handlersMap[key].title}</div>
                    </#list>
                </div>
                </div>
                <span id="spanTestTag">
                    <label class="layui-form-label" style="padding-left: 0px; padding-right:0px;padding:7px 0px; text-align: left">测试标签：</label>
                    <div class="layui-input-block" style="float: left; min-height: 30px; float: left;margin-left: 10px;">
                        <input type="text" id="testStatusTag" name="testStatusTag" class="layui-input">
                    </div>
                </span>
            </td>
        </tr>
        <tr>
            <th>节点跳过设定:</th>
            <td >
                <div class="layui-input-block" id="skipSettingDiv" style="margin-left: 0px">
                    <#list skipMap?keys as key>
                    <input type="checkbox" lay-skin="primary" name="skipSetting" value="${key}"><div class='text-adjust'>${skipMap[key].title}</div>
                </#list>
                </div>
            </td>
        </tr>
    </table>
    <div id="windowUrls" style="display: none">
    </div>
</form>

    <script>
        layui.use(['setter','layer', 'form','jquery','table','laytpl','commons'], function() {
            var layer = layui.layer
                ,$ = layui.jquery
                ,form = layui.form
                ,setter=layui.setter
                ,table = layui.table
                ,laytpl = layui.laytpl
                ,commons = layui.commons
                ,element=layui.element;

            var modelId = "${modelId!}";
        var parentProcDefId = "${parentProcDefId}";
            $(function(){
                loadFlowVars();
                form.render();
                //初始化数据
                init();
            });

        function loadFlowVars(){
            $.ajax({
                url: serverPath.workflowPath + "/workflow/bpmDefVar/getFlowVars",
                type: "get",
                data:{modelId:modelId,parentProcDefId:parentProcDefId},
                contentType: 'application/json',
                dataType: 'json',
                success: function(result) {
                    if (commons._filterRecord(result)) {
                        var varsMap = result.data;
                        var getTpl = varTemplate.innerHTML;
                        laytpl(getTpl).render(varsMap, function(html){
                            $("#view").html(html);
                        });
                        form.render('select','otherParam');
                        form.on('select(selFlowVar)', function(data){
                            var value= data.value;
                            if(value!=""){
                                var text = $(data.elem).find("option[value="+value+"]").text();
                                var inStr="{"+text+":"+value+"}";
                                InsertText(inStr);
                            }
                        });
                    }
                }
            });
        }
        function InsertText(val){
            var str = $("#taskNameRule").val();
            $("#taskNameRule").val(str+val);
        }

        //提示信息
        $('#nextTask').hover(function () {
            layer.tips('流程启动后直接完成第一个节点的任务。', '#nextTask');
        },function () {
            layer.tips.close
        });
        $('#startHint').hover(function () {
            layer.tips('不使用表单直接启动流程，启动流程时不传入主键。', '#startHint');
        },function () {
            layer.tips.close
        });
        $('#choiceHint').hover(function () {
            layer.tips('如果勾选，那么流程启动时可以改变下一步的执行人，默认不可以。', '#choiceHint');
        },function () {
            layer.tips.close
        });
        $('#submitHint').hover(function () {
            layer.tips('如果勾选，在每一次提交提示确认对话框，默认关闭。', '#submitHint');
        },function () {
            layer.tips.close
        });
        $('#changeHint').hover(function () {
            layer.tips('如果勾选，则允许转办，默认不允许转办。', '#changeHint');
        },function () {
            layer.tips.close
        })
        $('#endHint').hover(function () {
            layer.tips('如果勾选，则允许转发，默认不允许。', '#endHint');
        },function () {
            layer.tips.close
        });
        $('#copyHint').hover(function () {
            layer.tips('如果勾选，则允许在流程结束时抄送，默认不抄送。', '#copyHint');
        },function () {
            layer.tips.close
        });
        $('#helpHint').hover(function () {
            layer.tips('流程帮助附件', '#helpHint');
        },function () {
            layer.tips.close
        });
        $('#printHint').hover(function () {
            layer.tips('如果勾选，则流程实例归档后将提供打印表单功能。', '#printHint');
        },function () {
            layer.tips.close
        });

        function flowList(){
            return $.map(layui.ownList,function(v){
                return {name:v.name,id:v.id};
            })
        }
        //隐藏或显示流程参考条数
        form.on("checkbox(allowReferChange)", function(data){
            spanInstanceAmountShowOrHide(data.elem.checked);
        });

        //隐藏或显示流程参考条数
        function spanInstanceAmountShowOrHide(b){
            if(b){
                $("#spanInstanceAmount").show();
            }else{
                $("#spanInstanceAmount").hide();
            }
        }

        //状态改变，消息类型与测试标签显示与隐藏
        form.on("select(statusChange)", function(data){
            statusChange(data.value);
            // 获取选中的值
        });

        //状态改变，消息类型与测试标签显示与隐藏
        function statusChange(status){
            if(status==1 || status==4){
                $("#spanMessage").show();
            }else{
                $("#spanMessage").hide();
            }
            if(status==4){
                $("#spanTestTag").show();
            }else{
                $("#spanTestTag").hide();
            }
        }

        //初始化数据
        function init(){
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath+"actDefModel/model/detail?modelId=${modelId!}",
                type: "get",
                dataType: 'json',
                success: function (data) {
                    var returnData = data.data;
                    //流程标题规则定义
                    var taskNameRule = returnData.taskNameRule;
                    $("#taskNameRule").val(taskNameRule);
                    //跳过第一个任务
                    var toFirstNode = returnData.toFirstNode==1?true:false;
                    if(toFirstNode){
                        $("#toFirstNode").prop("checked",true);
                        $("#toFirstNode").next().addClass("layui-form-checked");
                    }
                    //直接启动流程
                    var directstart = returnData.directstart==1?true:false;
                    if(directstart){
                        $("#directstart").prop("checked",true);
                        $("#directstart").next().addClass("layui-form-checked");
                    }
                    //流程启动选择执行人
                    var showFirstAssignee = returnData.showFirstAssignee==1?true:false;
                    if(showFirstAssignee){
                        $("#showFirstAssignee").prop("checked",true);
                        $("#showFirstAssignee").next().addClass("layui-form-checked");
                    }
                    //提交是否需要确认
                    var submitConfirm = returnData.submitConfirm==1?true:false;
                    if(submitConfirm){
                        $("#submitConfirm").prop("checked",true);
                        $("#submitConfirm").next().addClass("layui-form-checked");
                    }
                    //是否允许转办
                    var allowDivert = returnData.allowDivert==1?true:false;
                    if(allowDivert){
                        $("#allowDivert").prop("checked",true);
                        $("#allowDivert").next().addClass("layui-form-checked");
                    }
                    //是否允许我的办结转发
                    var allowFinishedDivert = returnData.allowFinishedDivert==1?true:false;
                    if(allowFinishedDivert){
                        $("#allowFinishedDivert").prop("checked",true);
                        $("#allowFinishedDivert").next().addClass("layui-form-checked");
                    }
                    //是否允许办结抄送
                    var allowFinishedCc = returnData.allowFinishedCc==1?true:false;
                    if(allowFinishedCc){
                        $("#allowFinishedCc").prop("checked",true);
                        $("#allowFinishedCc").next().addClass("layui-form-checked");
                    }
                    //抄送人员设置
                    var ccMessageType = returnData.ccMessageType;
                    $("input[name='ccMessageType']").val(ccMessageType);
                    //流程实例归档后是否允许打印表单
                    var isPrintForm = returnData.isPrintForm==1?true:false;
                    if(isPrintForm){
                        $("#isPrintForm").prop("checked",true);
                        $("#isPrintForm").next().addClass("layui-form-checked");
                    }
                    //是否允许参考
                    var allowRefer = returnData.allowRefer==1?true:false;
                    if(allowRefer){
                        $("#allowRefer").prop("checked",true);
                        $("#allowRefer").next().addClass("layui-form-checked");
                    }
                    //允许参考的实例数量
                    var instanceAmount = returnData.instanceAmount;
                    $("#instanceAmount").val(instanceAmount);
                    //流程状态
                    var status = returnData.status;
                    $("#status").val(status);
                    $("#status").next().find("dd[lay-value="+status+"]").addClass("layui-this");
                    var text = $("#status").next().find("dd[lay-value="+status+"]").text();
                    $("#status").next().find("input").attr("value",text);
                    //测试状态标签
                    var testStatusTag = returnData.testStatusTag;
                    $("#testStatusTag").val(testStatusTag);
                    //跳过设定
                    var skipSetting = returnData.skipSetting;
                    initCheckBox('skipSetting',skipSetting);
                    //归档时发送消息给发起人
                    var informStart = returnData.informStart;
                    initCheckBox('informStart',informStart);
                    //通知类型
                    var informType = returnData.informType;
                    initCheckBox('informType',informType);
                    //流程帮助  TODO 获取逻辑整理
                    var attachmentFileId = returnData.attachment;
                    if(attachmentFileId!=undefined && attachmentFileId!=0) {
                        initAttachment(attachmentFileId);
                    }

                    spanInstanceAmountShowOrHide(allowRefer);
                    statusChange(status);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                }
            });
        }

        /**
         * 初始化checkbox是否选中
         * @param name checkbox的name
         * @param initValue 从后台读取过来的值
         */
        function initCheckBox(name,initValue){
            if(initValue!=null && initValue!=null){
                $("input[name='"+name+"']").each(function(){
                    var value = $(this).attr("value");
                    if(initValue.indexOf(value)!=-1){
                        $(this).prop("checked",true);
                        $(this).next().addClass("layui-form-checked");
                    }
                });
            }
        }
        //初始化添加附件，流程帮助
        function initAttachment(_fileId) {
            $.ajax({
                url:serverPath.systemPath+setter.sysLinkPath+'attachFile/get'
                ,method:'get'
                ,data:{fileId:_fileId}
                ,dataType:'json'
                ,success:function (res) {
                    if(commons._filterRecord(res)) {
                        var _file = res.data;
                        showAttachment(true,_fileId,_file.fileName);
                    }
                }
            })
        }
        //删除附件，流程帮助
        $('#delAttachment').click(function (){showAttachment(false);})
        //附件回显，流程帮助
        function showAttachment(isShow,_fileId,_fileName) {
            if(isShow) {
                //添加附件or更新附件
                $("#attachment").val(_fileId);
                //TODO 下载触发事件
                // $('#selectedFileUrl').attr('href', "system/attachFile/download?fileId=" + _fileId);
                $('#selectedFileName').text(_fileName);
                $('#attachmentSpan').removeAttr('hidden');
            }else{
                //删除附件
                $("#attachment").val('');
                // $('#selectedFileUrl').attr('href', '');
                $('#selectedFileName').text('');
                $('#attachmentSpan').attr('hidden','hidden');
            }
        }
        function getCheckedValue(id){
            var checked=$(id).prop("checked");
            if(checked==undefined){
                return 0;
            }else if(checked){
                return 1;
            }else{
                return 0;
            }
        }

        function getMsgTypeList(id){
            var msgTypeList=[];
            $("input[name='"+id+"']").each(function(){
                var me = $(this),
                    val = me.val(),
                    state = me.prop("checked");
                if(state)
                    msgTypeList.push(val);
            });
            return msgTypeList;
        }

        //保存
        function saveParam(){
            var taskNameRule = $("#taskNameRule").val();
            var toFirstNode=getCheckedValue("#toFirstNode");
            var showFirstAssignee=getCheckedValue("#showFirstAssignee");
            var submitConfirm=getCheckedValue("#submitConfirm");
            var allowDivert=getCheckedValue("#allowDivert");
            var allowFinishedDivert=getCheckedValue("#allowFinishedDivert");
            var informStart = getMsgTypeList("informStart");
            var informType = getMsgTypeList("informType");
            var allowFinishedCc=getCheckedValue("#allowFinishedCc");
            var isPrintForm=getCheckedValue("#isPrintForm");
            var attachment=$('#attachment').val();
            var status=$('#status').val();

            var allowRefer=getCheckedValue("#allowRefer");
            var instanceAmount=$('#instanceAmount').val();
            var testStatusTag=$('#testStatusTag').val();

            var directstart=getCheckedValue("#directstart");
            var ccMessageType = $("input[name='ccMessageType']").val();

            var skipSetting=getMsgTypeList("skipSetting");

            var params={id:modelId,taskNameRule:taskNameRule,toFirstNode:toFirstNode,
                showFirstAssignee:showFirstAssignee,
                submitConfirm:submitConfirm,allowDivert:allowDivert,
                allowFinishedDivert:allowFinishedDivert,informStart:informStart.join(','),
                informType:informType.join(','),allowFinishedCc:allowFinishedCc,
                isPrintForm:isPrintForm,attachment:attachment,
                status:status,allowRefer:allowRefer,
                instanceAmount:instanceAmount,directstart:directstart,ccMessageType:ccMessageType,
                testStatusTag:testStatusTag,
                skipSetting:skipSetting.join(',')};
            $.ajax({
                url:serverPath.workflowPath+setter.workflowLinkPath+"actDefModel/saveParam",
                type:"post",
                data:params,
                dataType: 'json',
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
        }

        $('.otherParam .save').click(function () {
            saveParam();
        });
        //全局使用。即所有弹出层都默认采用，但是单个配置skin的优先级更高
        layer.config({
            skin: 'btn-class'
        });
        /**
         * 添加附件 按钮触发
         * 具体用途：附件上传(流程帮助)
         */
        $(".selectedFile").click(function () {
            layer.open({
                type: 2,
                title: "上传",
                shade: 0.3,
                area: ['400px', '300px'],
                content: serverPath.systemPath+setter.sysLinkPath + "attachFile/view/importXml"
            })
        });

        /**
         * 附件文件 点击事件
         * 具体用法：附件文件下载(流程帮助)
        */
        $("#selectedFileUrl").click(function () {
            layer.confirm('确定下载【'+($('#selectedFileName').val()!=undefined?this.text:null)+'】吗？', {
                btn: ['是', '否'] //按钮
            }, function (index) {
                var _fileId = $('#attachment').val();
                if(_fileId==undefined||_fileId==''){
                    layer.msg("附件不存在，请重新选择！",{icon:5,time:1000});
                }else {
                    window.open(serverPath.systemPath + setter.sysLinkPath + "attachFile/download?fileId=" + _fileId);
                }
                layer.close(index);
            });
        });
        //    抄送人员设置
        var dataTable = [{"username":"user-0","sex":"女"},{"username":"user-1","sex":"女"},{"username":"user-2","sex":"女"},{"username":"user-3","sex":"女"},{"username":"user-4","sex":"女"},{"username":"user-5","sex":"女"},{"username":"user-6","sex":"女"},{"username":"user-7","sex":"女"},{"username":"user-8","sex":"女"},{"username":"user-9","sex":"女"},{"username":"user-10","sex":"女"},{"username":"user-11","sex":"女"},{"username":"user-12","sex":"女"},{"username":"user-13","sex":"女"},{"username":"user-14","sex":"女"},{"username":"user-15","sex":"女"},{"username":"user-16","sex":"女"},{"username":"user-17","sex":"女"},{"username":"user-18","sex":"女"},{"username":"user-19","sex":"女"}]
        $(".copyingPeople").click(function () {
            var windowUrl = '${ctx}/workflow/actDefModel/view/otherParamCopier?modelId='+modelId;
            $('#windowUrls').load(windowUrl,{},function(response,status,xhr){
                layer.open({
                    type:1,
                    title:"抄送人员设置",
                    content:$('#windowUrls'),
                    area:['980px','620px'],
                    shade: 0.3,
                    btn:["保存","删除","添加","编辑","保存批次号"],
                    success:function(layero){
                        $(".layui-layer-shade").after(layero);
                    },
                    yes: function(index, layero){
                        //按钮【保存】的回调
                        if($("input[name=inner]").prop('checked')){
                            $("input[name='ccMessageType']").val('{"inner":1,"mail":0,"sms":0}');
                        }else {
                            $("input[name='ccMessageType']").val('{"inner":0,"mail":0,"sms":0}');
                        }
                        layer.msg('保存成功！', {icon: 6, time: 1000})
                        layer.close(index);
                    }
                    ,btn2: function(index, layero){
                        //按钮【删除】的回调
                        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
                        var conditionIds = ''
                        layer.confirm('确定删除吗？',{title:'提示'}, function(index) {
                            $.each(checkStatus.data,function (k,v) {
                                conditionIds += v.id + ','
                            });
                            conditionIds = conditionIds.substring(0,conditionIds.length-1);
                            $.ajax({
                                type:"post",
                                dataType:"json",
                                url : serverPath.workflowPath + "/workflow/bpmUserCondition/del",
                                data : {'conditionIds':conditionIds},
                                success: function (result) {
                                    layer.msg(result.msg,{icon: 1,time:1000});
                                    //表格重载
                                    table.reload('idTest'); //只重载数据
                                }
                            })
                        });
                        return false// 开启该代码可禁止点击该按钮关闭
                    }
                    ,btn3: function(index, layero){
                        //按钮【添加】的回调
                        elasticFrameAdd();
                        return false //禁止点击该按钮关闭
                    }
                    ,btn4: function(index, layero){
                        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
                        // if (checkStatus.data.length>0)
                        var conditionIds = ''
                        //按钮【编辑】的回调
                        elasticFrameEdit(checkStatus);
                        return false //禁止点击该按钮关闭
                    }
                    ,btn5: function(index, layero){
                        //按钮【保存批次号】的回调
                        var conditionIds = [];
                        var groupNos = [];
                        $("td[data-field=groupNo]").each(function () {
                            var _this = $(this);
                            var groupNo = _this.children().text();
                            var tr = _this.closest("tr");
                            var conditionId = $('td[data-field=id]',tr).children().text();
                            conditionIds.push(conditionId);
                            groupNos.push(groupNo);
                        });
                        if(conditionIds.length == 0){ return; }
                        $.ajax({
                            url: serverPath.workflowPath + "/workflow/bpmUserCondition/updateGroup"
                            ,method:'post'
                            , data: {'conditionIds': conditionIds.join(","), 'groupNos': groupNos.join(",")}
                            , dataType: 'json'
                            , success: function (res) {
                                if (commons._filterRecord(res)) {
                                    layer.msg(res.msg, {icon: 6});
                                } else {
                                    layer.msg(res.msg, {icon: 5});
                                }
                            }
                        });
                        return false //禁止点击该按钮关闭
                    }
                });
            })

        });
        //添加
        function elasticFrameAdd() {
            //人员规则类型
            var conditionType = 1;
            //回显Id,编辑按钮时启用 TODO 从弹窗获取
            var conditionId ='';
            //Url路径+传参
            var windowUrl = 'actDefModel/view/userSetUpdate?modelId=' + modelId + '&parentProcDefId=' + parentProcDefId + '&conditionType=' + conditionType;
            if(conditionId!='') {
                windowUrl = windowUrl+'&conditionId='+conditionId
            }
            var iframeWin;
            parent.layer.open({
                title:'配置节点人员',
                type: 2,
                shade: 0.3,
                area: ['1000px', '700px'],
                content: serverPath.workflowPath + setter.workflowLinkPath +windowUrl,
                skin: 'btn-class',
                btn:["保存","关闭"],
                end: function(layero, index){
                    // element.tabChange('commonSetting', "userSet");
                },
                yes:function (index,layero) {
                    //得到iframe页的窗口对象
                    iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    function closeUser() {
                        parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                    iframeWin.save(closeUser,reload);
                }
            });
        };
        //修改
        function elasticFrameEdit(checkStatus) {
            //是否被选中
            if(checkStatus.data.length==0||checkStatus.data.length>1){
                layer.alert('请选择一条要修改的记录!');
                return ;
            }
            var conditionId=checkStatus.data[0].id;
            //打开弹窗传值过去
            parent.layer.open({
                title:'修改节点人员',
                type:2,
                shade:0.3,
                btn:["保存","关闭"],
                skin: 'btn-class',
                area:  ['1000px', '700px'],
                content:serverPath.workflowPath + setter.workflowLinkPath +"actDefModel/view/userSetUpdate?modelId="+modelId+"&&parentProcDefId=${parentProcDefId}&&conditionId="+conditionId,
                end: function(layero, index){
                    // element.tabChange('commonSetting', "userSet");
                },
                yes:function (index,layero) {
                    //获取iframe的body元素
                    var body = layer.getChildFrame('body',index);
                    //得到iframe页的窗口对象
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    function closeUser() {
                        parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                    //执行iframe页的save方法
                    iframeWin.save(closeUser,reload);
                }
            });
        };
        function reload() {
            //表格重载
            table.reload('idTest'); //只重载数据
        }
        //上移 下移
        function sortTr(obj,up){
            var thisTr = $(obj).parents("tr");
            if(up){
                var prevTr = $(thisTr).prev();
                if(prevTr){
                    thisTr.insertBefore(prevTr);
                }
            } else {
                var nextTr = $(thisTr).next();
                if(nextTr){
                    thisTr.insertAfter(nextTr);
                }
            }
        };
        /*删除数组中的某一个对象
        _arr:数组
        _obj:需删除的对象
        */
        function removeAaary(_arr, _obj) {

            var length = _arr.length;
            for (var i = 0; i < length; i++) {
                if (_arr[i].username == _obj[i].username) {
                    if (i == 0) {
                        _arr.shift(); //删除并返回数组的第一个元素
                        return _arr;
                    }
                    else if (i == length - 1) {
                        _arr.pop();  //删除并返回数组的最后一个元素
                        return _arr;
                    }
                    else {
                        _arr.splice(i, 1); //删除下标为i的元素
                        return _arr;
                    }
                }
            }
        }


        });
    </script>
